﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DBUtility;
using CommonFunc;

public partial class Control_ProductList1 : System.Web.UI.UserControl
{
    MODEL.ProductClass MPC = new MODEL.ProductClass();
    MODEL.ProductClass _MPC = new MODEL.ProductClass();

    BLL.ProductClass BPC = new BLL.ProductClass();

    AutoPage AP = new AutoPage();

    protected void Page_Load(object sender, EventArgs e)
    {
        ControlDataInit();
    }


    #region ControlDataInit
    protected void ControlDataInit()
    {
        try
        {
            string SQLstr;

            if (Request.QueryString["ClassID"] == null)
            {
                SQLstr = "SELECT * FROM [Product] WHERE [Product_IsLock]=False ";
                SQLstr += " AND [Product_IsDel]=False ";
            }
            else
            {
                MPC.PC_ID = Convert.ToInt32(Request.QueryString["ClassID"]);
                _MPC = BPC.GetDataByID(MPC);

                SQLstr = "SELECT * FROM [Product] WHERE [Product_ClassCode] LIKE '" + _MPC.PC_ClassCode + "%' ";
                SQLstr += " AND [Product_IsLock]=False AND [Product_IsDel]=False";
            }

            if (Request.QueryString["Act"] == "Search")
            {
                SQLstr += " AND [Product_Title] LIKE '%" + Request.QueryString["Title"].ToString() + "%' ";
            }


            SQLstr += " ORDER BY [Product_Order] DESC";

            DataTable DT_ProductList1 = AccHelper.GetDataTable(SQLstr);
            PagedDataSource pds = new PagedDataSource();
            pds.AllowPaging = true;
            AspNetPager1.RecordCount = DT_ProductList1.Rows.Count;
            pds.PageSize = AspNetPager1.PageSize;
            pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;
            pds.DataSource = DT_ProductList1.DefaultView;
            DL_ProductList.DataSource = pds;
            DL_ProductList.DataBind();
        }
        catch (Exception ex)
        {
            LB_ProductList1.Text = ex.Message;
        }
    }
    #endregion

    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        ControlDataInit();
    }

    #region 产品图片 [格式化]
    protected string FormatImage(object _Image)
    {
        string ImageURL = Convert.ToString(_Image);

        if (ImageURL == "")
        {
            return "Manageweb/images/null.jpg";
        }
        else
        {
            return "UploadImage/" + ImageURL;
        }
    }
    #endregion
}
